import time

from selenium.webdriver.support.ui import WebDriverWait
class Base():
    # 初始化驱动
    def __init__(self,driver):
        self.driver=driver
    # 封装打开网址方法
    def open_url(self,url):
        self.driver.get(url)
    # 显示等待
    def find_element(self,loc):
        try:
          WebDriverWait(self.driver,20,0.5).until(lambda driver: driver.find_element(*loc).is_displayed)
          return self.driver.find_element(*loc)
        except Exception as e:
            str=time.strftime('%Y%m%d%H%M%S')
            self.driver.save_screenshot(str+'jiuxian.png')
            print(e)
    # 输入事件
    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)
    # 点击事件
    def click(self,loc):
        self.find_element(loc).click()
    # 文本事件
    def text(self,loc):
        return self.find_element(loc).text
    # 多窗口切换
    def windows(self):
        self.driver.switch_to.window(self.driver.window_handles[-1])
    # frame框架
    def frame(self,loc):
        self.driver.switch_to.frame(self.driver.find_element(loc))
    # 下滑底部
    def  scroll_down(self):
        self.driver.execute_script(f'window.scrollTo(0,document.body.scrollHeight)')

    def scroll_x(self,x):
        self.driver.execute_script(f'window.scrollTo(0,{x})')




